<!DOCTYPE html>
<html>
<head>
    <title>门诊医生--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">


    </script>
</head>
<body>

<form id="myForm" action="" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">医生编号：</td>
            <td><input type="text" name="doctorId" value=""/></td>

            <td width="10%" class="tableleft">医生姓名：</td>
            <td><input type="text" name="doctorName" value=""/></td>

            <td width="10%" class="tableleft">科室：</td>
            <td><input type="text" name="doctorKeshi" value=""/></td>
        </tr>
        <tr>
            <td colspan="6">
                <center>
                    <button onclick="loadData()" type="button" class="btn btn-primary">查询</button>
                    <button type="reset" class="btn btn-primary">清空</button>
                </center>
            </td>
        </tr>
    </table>
</form>

    <table class="table table-bordered table-hover definewidth m10">
        <thead>
        <tr>
            <th><input type="checkbox" id="checkall" onChange="checkall();"></th>
            <th>医生编号</th>
            <th>医生姓名</th>
            <th>入院时间</th>
            <th>所属科室</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tboby">
        <tr>
            <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1106</td>
            <td style="vertical-align:middle;">欧阳雨露</td>
            <td style="vertical-align:middle;">2014-09-05 12：12：12</td>
            <td style="vertical-align:middle;">急诊科</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>
            </td>
        </tr>
        <tr>
            <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1107</td>
            <td style="vertical-align:middle;">艾小天</td>
            <td style="vertical-align:middle;">2014-02-09 12：12：11</td>
            <td style="vertical-align:middle;">妇科</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>
            </td>
        </tr>
        </tbody>
    </table>

    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <th colspan="5">
                <div style=" display: inline-block">
                    <button type="button" class="btn btn-success" id="newNav">添加新医生</button>
                    <button type="button" class="btn btn-success" id="delPro">导出Excel</button>
                </div>
                <!--分页部分-->
                <div style=" display: inline-block;margin-left: 100px">
                    <div style="text-align: left;display: inline-block;">
                        <ul class="pagination" style="margin: 0;display: inline">
                            <li name="pageLi" id="firstPage" style="display: inline"><a href="#">首页</a></li>
                            <li name="pageLi" id="prePage" style="display: inline"><a href="#">上一页</a></li>
                            <li name="pageLi" id="nextPage" style="display: inline"><a href="#">下一页</a></li>
                            <li name="pageLi" id="lastPage" style="display: inline"><a href="#">末页</a></li>
                        </ul>
                    </div>
                    <label style="text-align: right;margin-left: 15px;display: inline-block">
                        共<span id="total"></span>条数据，共<span id="pages"></span>页
                    </label>
                    <label style="text-align: right;margin-left: 10px">
                        每页显示
                    </label>
                    <div style="text-align: right; padding:0;margin: 0; display: inline">
                        <select onblur="loadData()" name="pageSize" id="pageSize" style="width: 80px;">
                            <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="15">15</option>
                        </select>
                    </div>
                    <label style="text-align: left;width: 87px;padding: 8px 5px;">
                        条数据
                    </label>
                    <label style="text-align: right;margin-left: 0px">
                        跳转到第
                    </label>
                    <div style="text-align: right; padding:0;margin: 0;display: inline">
                        <input onblur="loadData()" style="width: 50px" name="pageNum" id="pageNum" value="1"/>
                    </div>
                    <label style="text-align: left">页</label>
                </div>
            </th>
        </tr>
    </table>

</body>
</html>
<script>
    //页面加载完毕之后发送异步请求
    $(function () {
        loadData();
        $("ul[class='pagination']>li").click(function () {
            let num = $(this).attr("name");
            $("input[name='pageNum']").val(num);
            loadData();
        });
        //跳转添加页面
        $('#newNav').click(function () {
            window.location.href = "add.html";
        });

    });

    //加载数据
    function loadData() {
        let url = document.location.toString();
        let pageNum = url.GetValue("pageNum");
        let pageSize = url.GetValue("pageSize");
        if (pageNum != null && $("input[name='pageNum']").val() != null) {
            $("input[name='pageNum']").val(pageNum);
        }
        if (pageSize != null && $("select[name='pageSize']").val() != null) {
            $("select[name='pageSize']").val(pageSize);
        }
        //优化pageSize和pageNum的传值
        let pageNum2 = $("#pageNum").val();
        let pageSize2 = $("#pageSize").val();
        //alert($("#myForm").serialize())
        $.ajax({
            type: "GET",
            url: "/hospital/doctor/list",
            data:  $.param({pageNum:pageNum2,pageSize:pageSize2})+'&'+$("#myForm").serialize(),
            dataType: "json",
            success: function (vo) {
                // alert( "Data Saved: " + vo );
                let list = vo.pageInfo.list;
                // alert( "Data lsit: " + list );
                let str = "";
                for (let i = 0; i < list.length; i++) {
                    let obj = list[i];
                    let dId = obj.dId;
                    let dName = obj.dName;
                    let dIdcar = obj.dIdcar;
                    let dPhone = obj.dPhone == 1 ? "男" : "女";
                    let dTelphone = obj.dTelphone;
                    let dSex = obj.dSex;
                    let dBirthday = obj.dBirthday;
                    let dAge = obj.dAge;
                    let dEmail = obj.dEmail;
                    let dKeshi = obj.dKeshi;
                    let dXueli = obj.dXueli;
                    let dDesc = obj.dDesc;
                    let dIntime = obj.dIntime;
                    let dState = obj.dState;
                    let btnStr = "";
                    if (obj.dState == 0) {
                        btnStr = '<a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>&nbsp;'
                    } else {
                        //continue
                        btnStr = '<a href="edit.html">已删除</a>';
                    }
                    str += '<tr>\n' +
                        '        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>\n' +
                        '        <td style="vertical-align:middle;">' + dId + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + dName + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + dIntime + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + dKeshi + '</td>\n' +
                        '        <td style="vertical-align:middle;"><a href="" onclick="updateDoctor(' + dId + ')">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="" onclick="updateDoctor2(' + dId + ')">更改</a>&nbsp;&nbsp;&nbsp;<a href="" onclick="deleteDoctor(' + dId + ')">删除</a></td>\n' +
                        '    </tr>'
                }
                $("#tboby").html(str);
                //填充分页数据
                fillPageData(vo.pageInfo);

            }

        });
    }

    //填充数据
    function fillPageData(pageInfo) {
        //填充信息
        $("#total").html(pageInfo.total);
        $("#pages").html(pageInfo.pages);
        $("input[name='pageNum']").val(pageInfo.pageNum);
        $("select[name='pageSize']").val(pageInfo.pageSize);
        //设置按钮的属性值和样式
        $("#firstPage").attr("name", 1);
        $("#prePage").attr("name", pageInfo.prePage);
        $("#nextPage").attr("name", pageInfo.nextPage);
        $("#lastPage").attr("name", pageInfo.pages);
        $("#firstPage").removeClass("disabled");
        $("#prePage").removeClass("disabled");
        $("#firstPage").removeClass("disabled");
        $("#prePage").removeClass("disabled");
        if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
            $("#firstPage").addClass("disabled");
            $("#prePage").addClass("disabled");
        }
        if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
            $("#nextPage").addClass("disabled");
            $("#lastPage").addClass("disabled");
        }
    }

    String.prototype.GetValue = function (para) {
        let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?") + 1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    //通过id回显详细信息
    function updateDoctor(id) {
        let pageNum = $("input[name='pageNum']").val();
        let pageSize = $("select[name='pageSize']").val();
        window.location.href = "/doctor/look.html?doctorId=" + id + "&pageNum=" + pageNum + "&pageSize=" + pageSize;
        window.event.returnValue = false;
    }

    //通过id回显更新信息
    function updateDoctor2(id) {
        let pageNum = $("input[name='pageNum']").val();
        let pageSize = $("select[name='pageSize']").val();
        window.location.href = "/doctor/edit.html?doctorId=" + id + "&pageNum=" + pageNum + "&pageSize=" + pageSize;
        window.event.returnValue = false;
    }

    //通过id删除
    function deleteDoctor(id) {
        let pageNum = $("input[name='pageNum']").val();
        let pageSize = $("select[name='pageSize']").val();
        if (confirm("确定要删除吗？")) {
            $.ajax({
                type: "POST",
                url: "/hospital/doctor/" + id,
                data: "_method=DELETE",
                success: function (vo) {
                    if (vo.code == 200) {

                        window.location.href = "/doctor/index.html?pageNum=" + pageNum + "&pageSize=" + pageSize;
                        window.event.returnValue = false;
                    } else {
                        alert(vo.msg);
                    }
                }
            });
        } else {
            window.location.href = "/doctor/index.html?pageNum=" + pageNum + "&pageSize=" + pageSize;
            window.event.returnValue = false;
        }
    }

    //全选
    function checkall() {
        var alls = document.getElementsByName("check");
        var ch = document.getElementById("checkall");
        if (ch.checked) {
            for (var i = 0; i < alls.length; i++) {
                alls[i].checked = true;
            }
        } else {
            for (var i = 0; i < alls.length; i++) {
                alls[i].checked = false;
            }
        }
    }

    //全删除
    function delAll() {
        var alls = document.getElementsByName("check");
        var ids = new Array();
        for (var i = 0; i < alls.length; i++) {
            if (alls[i].checked) {
                ids.push(alls[i].value);
            }
        }
        if (ids.length > 0) {
            if (confirm("确认操作?")) {
                alert("成功!");
            }
        } else {
            alert("请选中要操作的项");
        }
    }

</script>